package com.lbj.googleplay.googleplay100.ui.holder;

import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.lbj.googleplay.googleplay100.R;
import com.lbj.googleplay.googleplay100.domain.CategoryInfo;
import com.lbj.googleplay.googleplay100.http.HttpHelper;
import com.lbj.googleplay.googleplay100.utils.UIUtils;

import org.xutils.ImageManager;
import org.xutils.x;

public class CategoryHolder extends BaseHolder<CategoryInfo> implements View.OnClickListener{

    private TextView tvName1,tvName2,tvName3;

    private ImageView ivIcon1,ivIcon2,ivIcon3;

    private LinearLayout ll_grid1,ll_grid2,ll_grid3;

    private ImageManager imageManager;

    @Override
    public View initView() {
        View view = UIUtils.inflate(R.layout.list_item_category);
         ivIcon1 = view.findViewById(R.id.iv_icon1);
         ivIcon2 = view.findViewById(R.id.iv_icon2);
         ivIcon3 = view.findViewById(R.id.iv_icon3);
         tvName1 = view.findViewById(R.id.tv_name1);
         tvName2 = view.findViewById(R.id.tv_name2);
         tvName3 = view.findViewById(R.id.tv_name3);
         ll_grid1 = view.findViewById(R.id.ll_grid1);
         ll_grid2 = view.findViewById(R.id.ll_grid2);
         ll_grid3 = view.findViewById(R.id.ll_grid3);
         imageManager = x.image();
        return view;
    }

    @Override
    public void refreshView(CategoryInfo data) {
            tvName1.setText(data.name1);
            tvName2.setText(data.name2);
            tvName3.setText(data.name3);
            imageManager.bind(ivIcon1, HttpHelper.URL+"image?name="+data.url1);
            imageManager.bind(ivIcon2,HttpHelper.URL+"image?name="+data.url2);
            imageManager.bind(ivIcon3,HttpHelper.URL+"image?name="+data.url3);

    }

    @Override
    public void onClick(View v) {

        CategoryInfo info = getData();

        switch (v.getId()){
            case R.id.ll_grid1:
                Toast.makeText(UIUtils.getContext(), info.name1, Toast.LENGTH_SHORT).show();
                break;
            case R.id.ll_grid2:
                Toast.makeText(UIUtils.getContext(), info.name2, Toast.LENGTH_SHORT).show();

                break;
            case R.id.ll_grid3:
                Toast.makeText(UIUtils.getContext(), info.name3, Toast.LENGTH_SHORT).show();

                break;
            default:
                break;
        }
    }
}
